package com.origin.onlinesys.web.controllers.modules.account;

import com.origin.onlinesys.common.controllers.BaseController;
import com.origin.onlinesys.domain.modules.interviewsys.MenuBean;
import com.origin.onlinesys.service.modules.user.impl.MenuServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by origin on 15-3-20.
 * 菜单
 */
@Controller
@RequestMapping(value = "/management/menu")
public class MenuController extends BaseController{
    @Autowired
    private MenuServiceImpl service;

    @RequestMapping(value = "/add")
    public @ResponseBody
    MenuBean addMenu(@ModelAttribute MenuBean menu){
        if (menu.getParentId()==null||"".equals(menu.getParentId())){
            menu.setParentId("0");
        }
        if(menu.getId() == null){
            menu.setState("1");
            service.save(menu);
        }else{
            service.update(menu);
        }this.delNavRole();
        return menu;
    }

    @RequestMapping(value = "/del")
    public @ResponseBody
    int delMenu(String id){
        MenuBean menu = new MenuBean();
        menu.setId(id);menu.setState("2");service.update(menu);
        this.delNavRole();
        return 1;
    }

    @RequestMapping(value = "/findAll")
    public @ResponseBody
    List<MenuBean> findAll(){
        return service.selectAll();
    }

    @RequestMapping(value = "/findItem")
    public @ResponseBody
    List<MenuBean> findItem(String yn){
        return service.selectItem(yn);
    }
}
